import Router from 'koa-router'
import httpErrors from '../../../../core/HttpException'
import Auth from '../../../../middlewares/Auth'
import validator from '../../../../middlewares/validator'
import Mysql from '../../../../core/Mysql'
import editComponentAttrById from '../../../../common/apiValidate/lowCode/component/editComponentAttrById'

const router = new Router({
  prefix: '/api/v1/lowCode/component',
})

/*
 * 修改看板属性
 * @return
 */
router.post(
  '/editComponentAttrById',
  Auth.verifyTokenPermission,
  validator(editComponentAttrById, 'body'),
  async (ctx, next) => {
    const { id, name, parentId } = ctx.request.body
    await Mysql.command(`
    UPDATE
      component
    SET name = "${name}", parent_id = ${parentId}
    WHERE id = ${id}
  `)
    throw new httpErrors.Success()
  }
)

export default router
